package com.zxj.shop.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxj.shop.admin.entity.Role;
import com.zxj.shop.admin.exception.ServiceException;
import com.zxj.shop.admin.mapper.RoleMapper;
import com.zxj.shop.admin.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleMapper roleMapper;

	@Override
	public List<Role> getRoles() {
		return roleMapper.selectList(new QueryWrapper<>());
	}

	@Override
	public List<Role> getUserRoles(String userId) {
		return roleMapper.getUserRoles(userId);
	}

	@Override
	public IPage<Role> page(Page<Role> rolePage, Role role) {
		return roleMapper.selectPage(rolePage, new QueryWrapper<>());
	}

	@Override
	public Role getRoleById(Integer id) {
		Role role = roleMapper.selectById(id);
		if(role == null) {
			throw new ServiceException("角色不存在");
		}
		return role;
	}


}
